import React from 'react';
import {Spin, Card, Button, Table, Row, Col, Form} from 'antd';
import DescriptionList from 'ant-design-pro/lib/DescriptionList';
import PropTypes from 'prop-types';
import {saleOrderPriceTerms, saleOrderTransportType, paymentType, currency, proformaInvoiceSource} from '../Enum';
import routes from './routes';
import {DATE_FORMAT, TABLE, FORM_OPTIONS} from '../constants';
import {conventEnumValueToString, formatDateTime, formatAmount, formatPercent} from '../utils';
import {getDetail, confirmData} from './api';
import {injectIntl} from './intl';
import FileUpload from './FileUpload';
import styles from './style.css';
import {PERMISSION} from './constants';
import {hasPermissions} from './utils';
import {confirmValidator} from './validator';
import Return from '../common/Return';
import TextInput from 'Shared/components/TextInput';
const {Description} = DescriptionList;
const EMPTY_ARRAY = [];
const FormItem = Form.Item;
class ConfirmPanel extends React.PureComponent {
    state = {
        loading: false,
        hasOperat: false,
        validate: false,
        data: {commodity: 'Chery brand passenger car'},
        details: [],
    }
    componentDidMount() {
        this.getDetailInfo();
    }
    componentWillUnmount() {
        this.isunmount = true;
    }
    getDetailInfo = () => {
        const id = this.props.id;
        this.setState({loading: true});
        getDetail(id)
            .then(res => {
                if(res.ok)
                    this.setState({
                        loading: false,
                        data: res.data,
                        details: res.data.saleProformaInvoiceDetails.map(d => Object.assign({}, d, {
                            order: res.data.saleProformaInvoiceDetails.findIndex(x => x.id === d.id) + 1,
                        })),
                    });
                else
                    this.setState(({
                        loading: false
                    }));
            });
    }
    
    removeFilePath = file => {
        const data = this.state.data;
        const index = data.attachments.findIndex(item => item.fileId === file.fileId);
        if(index === -1)
            return null;
        const attachments = data.attachments || [];
        attachments.splice(index, 1);
        if(!this.state.hasOperat)
            this.setState({
                data: {
                    ...data,
                    attachments
                },
                hasOperat: true,
            });
    }
    onChange = (value, name) => {
        const data = Object.assign({}, this.state.data, {
            [name]: value
        });
        this.setState({
            data,
            hasOperat: true
        });
    }
    onChangeUpload = value => {
        const data = this.state.data;
        const attachments = data.attachments || [];
        attachments.push(value[0]);
        if(!this.state.hasOperat)
            this.setState({
                data: {
                    ...data,
                    attachments
                },
                hasOperat: true,
            });
    }
    onSubmit = () => {
        this.setState({
            loading: true
        });
        const {data} = this.state;
        const condition = {
            rowVersion: data.rowVersion,
            confirmIdea: data.confirmIdea,
            remark: data.remark,
            attachments: (data.attachments || []).map(v => ({
                fileId: v.fileId,
                fileName: v.fileName
            }))
        };
        const isValid = confirmValidator(condition);
        if(!isValid) {
            this.setState({
                validate: true,
                loading: false
            });
            return;
        }
        confirmData(data.id, condition).then(res => {
            if(res.ok)
                this.props.successReturn();
            if(!this.isunmount)
                this.setState({loading: false});
        });
    }
    onCancel = () => {
        this.props.history.push(routes.query.url());
    }
    onClickReturnBtn = () => {
        this.props.onCancel();
    }
    render() {
        const {data, details, loading, validate} = this.state;
        const validateConfirmIdea = !data.confirmIdea && validate ? 'error' : null;
        const confirmable = !hasPermissions(PERMISSION.confirm, this.props.permissions);
        const {formatMessage} = this.props.intl;
        let totalAmount = 0;
        let totalQuantity = 0;
        let totalShipmentAmount = 0;
        let totalInsuranceAmount = 0;
        let totalAmountSum = 0;
        if(details)
            details.forEach(v => {
                totalAmount += v.totalPrice;
                totalQuantity += v.quantity;
                totalShipmentAmount += v.shipmentAmountSum;
                totalInsuranceAmount += v.insuranceAmountSum;
                totalAmountSum += v.amountSum;
            });
        const columns = [{
            title: formatMessage({
                id: 'confirmPanel.column.order',
                defaultMessage: '序号'
            }),
            dataIndex: 'order',
        }, {
            title: formatMessage({
                id: 'confirmPanel.column.sourceCode',
                defaultMessage: '源单据编号'
            }),
            dataIndex: 'sourceCode',
        }, {
            title: formatMessage({
                id: 'confirmPanel.column.productGroupCode',
                defaultMessage: '物料组编号'
            }),
            dataIndex: 'productGroupCode',
        }, {
            title: formatMessage({
                id: 'confirmPanel.column.productGroupName',
                defaultMessage: '物料组名称'
            }),
            dataIndex: 'productGroupName',
        }, {
            title: formatMessage({
                id: 'newPanel.column.productCode',
                defaultMessage: '产品编号'
            }),
            dataIndex: 'productCode',
        },
        {
            title: formatMessage({
                id: 'newPanel.column.color',
                defaultMessage: '颜色'
            }),
            dataIndex: 'color',
        }, {
            title: formatMessage({
                id: 'confirmPanel.column.quantity',
                defaultMessage: '数量'
            }),
            dataIndex: 'quantity',
        }, {
            title: formatMessage({
                id: 'confirmPanel.column.price',
                defaultMessage: '单价'
            }),
            dataIndex: 'price',
            render: text => formatAmount(text)
        }, {
            title: formatMessage({
                id: 'confirmPanel.column.totalPrice',
                defaultMessage: '总价'
            }),
            dataIndex: 'totalPrice',
            render: text => formatAmount(text)
        }, {
            title: formatMessage({
                id: 'confirmPanel.column.amountSum',
                defaultMessage: '总金额'
            }),
            dataIndex: 'amountSum',
            render: text => formatAmount(text)
        }, {
            title: formatMessage({
                id: 'confirmPanel.column.remark',
                defaultMessage: '备注'
            }),
            dataIndex: 'remark',
        }];
        if(data.salesOrderPriceTerms === 3 || data.salesOrderPriceTerms === 5 || data.salesOrderPriceTerms === 6 || data.salesOrderPriceTerms === 2)
            columns.splice(7, 0,
                {
                    title: formatMessage({
                        id: 'confirmPanel.column.unitShipmentAmount',
                        defaultMessage: '单位运费'
                    }),
                    dataIndex: 'unitShipmentAmount',
                });
        if(data.salesOrderPriceTerms === 3 || data.salesOrderPriceTerms === 6)
            columns.splice(8, 0,
                {
                    title: formatMessage({
                        id: 'confirmPanel.column.unitInsuranceAmount',
                        defaultMessage: '单位保费'
                    }),
                    dataIndex: 'unitInsuranceAmount',
                });
        if(data.salesOrderPriceTerms === 3 || data.salesOrderPriceTerms === 5 || data.salesOrderPriceTerms === 6 || data.salesOrderPriceTerms === 2)
            columns.splice(9, 0,
                {
                    title: formatMessage({
                        id: 'confirmPanel.column.shipmentAmountSum',
                        defaultMessage: '总运费'
                    }),
                    dataIndex: 'shipmentAmountSum',
                });
        if(data.salesOrderPriceTerms === 3 || data.salesOrderPriceTerms === 6)
            columns.splice(10, 0,
                {
                    title: formatMessage({
                        id: 'confirmPanel.column.insuranceAmountSum',
                        defaultMessage: '总保费'
                    }),
                    dataIndex: 'insuranceAmountSum',
                });
        return (
            <div className="form-standard">
                <Spin spinning={this.state.loading}>
                    <Card title={formatMessage({
                        id: 'confirmPanel.column.common',
                        defaultMessage: '订单基本信息'
                    })}>
                        <Form>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirmPanel.operation.dataSource',
                                        defaultMessage: '数据来源'
                                    })}
                                    {...FORM_OPTIONS.item} >
                                        {conventEnumValueToString(proformaInvoiceSource, data.dataSource)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirmPanel.operation.code',
                                        defaultMessage: 'PI编号'
                                    })}
                                    {...FORM_OPTIONS.item} >
                                        {data.code}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={formatMessage({
                                            id: 'confirm.operation.brandId',
                                            defaultMessage: '品牌'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {(data.brandCode) + data.brandName}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirmPanel.operation.batchNumber',
                                        defaultMessage: '批次号'
                                    })}
                                    {...FORM_OPTIONS.item} >
                                        {data.batchNumber}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.dealerCode',
                                        defaultMessage: '总代编号'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.dealerCode}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.country',
                                        defaultMessage: '国家'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.country}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.marketDepartmentName',
                                        defaultMessage: '大区'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.marketDepartmentName}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'confirm.operation.countryOfOrigin',
                                            defaultMessage: '原产国'
                                        })} {...FORM_OPTIONS.item}>
                                        {data.countryOfOrigin}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'confirm.operation.countryOfDestination',
                                            defaultMessage: '目的国'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {data.countryOfDestination}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'confirm.form.address',
                                            defaultMessage: '地址'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {data.address}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.contactNumber',
                                        defaultMessage: '电话'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.contactNumber}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.zipCode',
                                        defaultMessage: '邮政编码'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.zipCode}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.cNPJ',
                                        defaultMessage: '法人国家登记号'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.cNPJ}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.contact',
                                        defaultMessage: '联系人'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.contact}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.tELEX',
                                        defaultMessage: '电传'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.tELEX}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.currency',
                                        defaultMessage: '币种'
                                    })} {...FORM_OPTIONS.item}>
                                        {conventEnumValueToString(currency, data.currency)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.tradeMethodName',
                                        defaultMessage: '贸易方式'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.tradeMethodName}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.salesOrderPriceTerms',
                                        defaultMessage: '价格条款'
                                    })} {...FORM_OPTIONS.item}>
                                        {conventEnumValueToString(saleOrderPriceTerms, data.salesOrderPriceTerms)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.paymentType',
                                        defaultMessage: '付款方式'
                                    })} {...FORM_OPTIONS.item}>
                                        {conventEnumValueToString(paymentType, data.paymentType)}
                                    </FormItem>
                                </Col>
                                {(data.saleOrderPriceTerms === 3 || 5 || 6 || 2) && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.shipmentAmount',
                                        defaultMessage: '运费汇总'
                                    })} {...FORM_OPTIONS.item}>
                                        {formatAmount(data.shipmentAmount)}
                                    </FormItem>
                                </Col>}
                                {(data.saleOrderPriceTerms === 3 || 6) && <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.insuranceAmount',
                                        defaultMessage: '保费汇总'
                                    })} {...FORM_OPTIONS.item}>
                                        {formatAmount(data.insuranceAmount)}
                                    </FormItem>
                                </Col>}
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.productAmount',
                                        defaultMessage: '清单总额'
                                    })} {...FORM_OPTIONS.item}>
                                        {formatAmount(data.productAmount)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.taxRate',
                                        defaultMessage: '税率'
                                    })} {...FORM_OPTIONS.item}>
                                        {formatPercent(data.taxRate)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.totalAmount',
                                        defaultMessage: 'PI金额'
                                    })} {...FORM_OPTIONS.item}>
                                        {formatAmount(data.totalAmount)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.deliveryTerms',
                                        defaultMessage: '运输方式'
                                    })} {...FORM_OPTIONS.item}>
                                        {conventEnumValueToString(saleOrderTransportType, data.deliveryTerms)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.payableAccount',
                                        defaultMessage: '到付账号'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.payableAccount}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.carrierName',
                                        defaultMessage: '指定货代'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.carrierName}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.shippingPortName',
                                        defaultMessage: '发运港口'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.shippingPortName}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.destinationPort',
                                        defaultMessage: '目的港口'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.destinationPort}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'confirm.form.estimatedDeliveryDate',
                                            defaultMessage: '预计交货日期'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {formatDateTime(data.estimatedDeliveryDate, DATE_FORMAT)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'confirm.form.validity',
                                            defaultMessage: '报价有效期'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {formatDateTime(data.validity, DATE_FORMAT)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'confirm.form.createTime',
                                            defaultMessage: '提报日期'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {formatDateTime(data.createTime, DATE_FORMAT)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.commodity',
                                        defaultMessage: 'PI描述'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.commodity}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.packing',
                                        defaultMessage: '包装描述'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.packing}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem label={formatMessage({
                                        id: 'confirm.operation.confirmor',
                                        defaultMessage: '确认人'
                                    })} {...FORM_OPTIONS.item}>
                                        {data.confirmor}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'confirm.form.confirmTime',
                                            defaultMessage: '确认时间'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {formatDateTime(data.confirmTime, DATE_FORMAT)}
                                    </FormItem>
                                </Col>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'confirm.form.confirmTime',
                                            defaultMessage: '确认时间'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        {formatDateTime(data.confirmTime, DATE_FORMAT)}
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'confirm.formC.confirmIdea',
                                            defaultMessage: '确认意见'
                                        })} {...FORM_OPTIONS.item} validateStatus={validateConfirmIdea} required>
                                        <TextInput
                                            name="confirmIdea"
                                            value={data.confirmIdea}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                            </Row>
                            <Row>
                                <Col {...FORM_OPTIONS.col}>
                                    <FormItem
                                        label={this.props.intl.formatMessage({
                                            id: 'confirm.form.remark',
                                            defaultMessage: '备注'
                                        })}
                                        {...FORM_OPTIONS.item}>
                                        <TextInput
                                            type="textarea"
                                            name="remark"
                                            value={data.remark}
                                            onBlur={this.onChange} />
                                    </FormItem>
                                </Col>
                            </Row>
                        </Form>
                    </Card>
                    <Card>
                        <DescriptionList size="large" title={<Row><Col span={12}>{formatMessage({
                            id: 'confirm.text.bankTitle',
                            defaultMessage: '银行信息'
                        })}</Col>
                        </Row>}>
                            <Description term={formatMessage({
                                id: 'confirm.text.bankAccount',
                                defaultMessage: '银行账号'
                            })}>{data.bankAccount}</Description>
                            <Description term={formatMessage({
                                id: 'confirm.text.bankName',
                                defaultMessage: '银行名称'
                            })}>{data.bankName}</Description>
                            <Description term={formatMessage({
                                id: 'confirm.text.bankNameEng',
                                defaultMessage: '银行英文名称'
                            })}>{data.bankNameEng}</Description>
                            <Description term={formatMessage({
                                id: 'confirm.text.bankAddress',
                                defaultMessage: '银行地址'
                            })}>{data.bankAddress}</Description>
                            <Description term={formatMessage({
                                id: 'confirm.text.sWIFT',
                                defaultMessage: '银行识别码'
                            })}>{data.swift}</Description>
                        </DescriptionList>
                    </Card>
                    <Card>
                        <DescriptionList size="large" title={formatMessage({
                            id: 'confirm.table.details',
                            defaultMessage: 'PI形式发票清单'
                        })}>
                            <Table
                                className="white-space-nowrap"
                                columns={columns}
                                rowKey="id"
                                pagination={false}
                                dataSource={details}
                                footer={() => <DescriptionList>
                                    <Description term={formatMessage({
                                        id: 'confirmPanel.operation.totalQuantity',
                                        defaultMessage: '数量汇总'
                                    })}>{totalQuantity}
                                    </Description>
                                    <Description term={formatMessage({
                                        id: 'confirmPanel.operation.totalAmount',
                                        defaultMessage: '总价汇总'
                                    })}><strong>{formatAmount(totalAmount)}</strong>
                                    </Description>
                                    {(data.salesOrderPriceTerms === 3 || data.salesOrderPriceTerms === 5 ||
                                        data.salesOrderPriceTerms === 6 || data.salesOrderPriceTerms === 2) && <Description term={formatMessage({
                                        id: 'confirmPanel.operation.totalShipmentAmount',
                                        defaultMessage: '运费汇总'
                                    })}>{formatAmount(totalShipmentAmount)}
                                    </Description>}
                                    {(data.salesOrderPriceTerms === 3 || data.salesOrderPriceTerms === 6) && <Description term={formatMessage({
                                        id: 'confirmPanel.operation.totalInsuranceAmount',
                                        defaultMessage: '保费汇总'
                                    })}>{formatAmount(totalInsuranceAmount)}
                                    </Description>}
                                    <Description term={formatMessage({
                                        id: 'confirmPanel.operation.totalAmountSum',
                                        defaultMessage: '金额汇总'
                                    })}><strong>{formatAmount(totalAmountSum)}</strong>
                                    </Description>
                                </DescriptionList>}
                                {...TABLE} />
                        </DescriptionList>
                    </Card>
                    <Card title={formatMessage({
                        id: 'reportPanel.title.files',
                        defaultMessage: '附件清单'
                    })}>
                        <Row>
                            <Col {...FORM_OPTIONS.col}>
                                <FileUpload onChange={this.onChangeUpload}
                                    onRemove={this.removeFilePath}
                                    fileList={data.attachments || EMPTY_ARRAY}/>
                            </Col>
                        </Row>
                    </Card>
                    <Card className={styles.optionBtn}>
                        <Button
                            type="primary"
                            onClick={this.onSubmit}
                            disabled={!confirmable}
                            loading={loading}>
                            {formatMessage({
                                id: 'confirm.operation.confirm',
                                defaultMessage: '确认'
                            })}
                        </Button>
                    </Card>
                </Spin>
                <div className="page-toolbar">
                    <Return
                        disabled={this.state.loading}
                        onConfirm={this.onClickReturnBtn}
                        showWarning={this.state.hasOperat} />
                </div>
            </div>
        );
    }
}

ConfirmPanel.propTypes = {
    history: PropTypes.object,
    id: PropTypes.string,
    intl: PropTypes.object
};

import {connect} from 'react-redux';
import {tableSearch} from './actions';
import selectorFactory from 'Shared/utils/immutableToJsSelectorFactory';
const getPermissions = selectorFactory(['page', 'domainData', 'permission', 'data']);
const mapStateToProps = state => ({
    permissions: getPermissions(state),
});
const mapDispatchToProps = (dispatch, props) => ({
    successReturn: () => {
        dispatch(tableSearch());
        props.history.push(routes.query.url());
    },
    onCancel: () => {
        props.history.push(routes.query.url());
    },
});
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(ConfirmPanel));
